<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="index.css"/>
		<link rel="stylesheet" type="text/css" href="../../../css/themes/bootstrap/easyui.css"/>
		<script src="../../../js/jquery-1.11.0.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../js/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../js/easyui-lang-zh_CN.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../js/dounine-tools.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<button onclick="create_floor();">创建楼层</button>
		<div id="product-floor">
			<div class="floors"></div>
		</div>
		
		<div id="floor-cell-dialog" title="图片信息" class="easyui-dialog" data-options="width:700,closed:true,buttons:'#floor-cell-dialog-buttons'">
			<form onsubmit="return false;">
				<table class="easyui-grid">
					<tr>
						<td>图片路径 :</td>
						<td>
							<input type="hidden" name="cell_id" />
							<input name="cell_picture" id="floor-picture" value="" class="easyui-textbox" />
						</td>
						<td>是否显示 :</td>
						<td>
							<input name="floor_display" value="" class="easyui-textbox" />
						</td>
					</tr>
					<tr>
						<td>楼层单元格高度:</td>
						<td>
							<input name="floor_cell_width" value="" class="easyui-textbox" />
						</td>
						<td>楼层单元格宽度:</td>
						<td>
							<input name="floor_cell_height" value="" class="easyui-textbox" />
						</td>
					</tr>
					<tr>
						<td>楼层列数:</td>
						<td>
							<input name="floor_column_count" value="" class="easyui-textbox" />
						</td>
						<td>楼层行数 :</td>
						<td>
							<input name="floor_row_count" value="" class="easyui-textbox" />
						</td>
					</tr>
				</table>
			</form>
			
		</div>
		<div id="floor-cell-dialog-buttons">
			<a href="javascript:void(0);" onclick="save_floor_cell();" class="easyui-linkbutton">保存</a>
			<a href="javascript:void(0);" onclick="cancel_floor_cell();" class="easyui-linkbutton">取消</a>
		</div>
		
		<div title="楼层信息" id="floor-info-dialog" class="easyui-dialog" data-options="width:700,closed:true,buttons:'#floor-info-dialog-buttons'">
			<form onsubmit="return false;">
				<table class="easyui-grid">
					<tr>
						<td>楼层名称 :</td>
						<td>
							<input type="hidden" name="floor_id" />
							<input name="floor_name" value="" class="easyui-textbox" />
						</td>
						<td>是否显示 :</td>
						<td>
							<input name="floor_display" value="" class="easyui-textbox" />
						</td>
					</tr>
					<tr>
						<td>楼层单元格高度:</td>
						<td>
							<input name="floor_cell_width" value="" class="easyui-numberspinner" />
						</td>
						<td>楼层单元格宽度:</td>
						<td>
							<input name="floor_cell_height" value="" class="easyui-numberspinner" />
						</td>
					</tr>
					<tr>
						<td>楼层列数:</td>
						<td>
							<input name="floor_column_count" value="" class="easyui-numberspinner" />
						</td>
						<td>楼层行数 :</td>
						<td>
							<input name="floor_row_count" value="" class="easyui-numberspinner" />
						</td>
					</tr>
				</table>
			</form>
		</div>
		<div id="floor-info-dialog-buttons">
			<a href="javascript:void(0);" onclick="save_floor_cell();" class="easyui-linkbutton">保存</a>
			<a href="javascript:void(0);" onclick="$('#floor-info-dialog').dialog('close');" class="easyui-linkbutton">取消</a>
		</div>
	</body>
</html>
<script type="text/javascript">
	var $floors = null,$floors_list=null,$floor_cell_width=100,$floor_cell_height=100,$floor_init_row=3,$floor_init_cell=10,$floor_click_cells=[],$floor_click_index=null,$floor_cell_operator_div_width=40,$floor_cell_operator_div_height=24;
	
	$floors = $("div.floors");
	
	$(function(){
		$.get('list.json',function(data){
				var list = data;
				for(var ii in list){
					var $item = list[ii];
					$.ajax({url:'a.html',method:'get',async:false,success:function(d){
						var _data = d.format({
							"floor_name":$item.floor_name,
							"floor-cell-width":$item.floor_cell_width,
							"floor-content-left":$item.floor_cell_width,
							"floor-content-values-left":$item.floor_cell_width,
							"floor-content-ul-height":$item.floor_cell_height
						});
						
						var $floor = $(_data).appendTo($floors);
						var $ul = $floor.find('div.floor-column ul');
						var $ul_lis = $ul.find('li');
						var $content = $floor.find('div.floor-content');
						var $content_title = $floor.find('div.floor-row');
						for(var j =1;j<=$item.floor_row_count;j++){
							$('<li onclick="click_floor_row(this);" enter="no" style="width:'+$item.floor_cell_width+'px;height:'+$item.floor_cell_height+'px;line-height:'+$item.floor_cell_height+'px;">'+j+'</li>').appendTo($content_title.find('ul'));//添加行序号
							if(j<$item.floor_row_count){//此处判断是为了减少多增的一行
								var cont = ['<ul style="top:'+(($item.floor_cell_height*j)+j)+'px;">'];
								cont.push('</ul>');
								$(cont.join('')).appendTo($content);
							}
						}
						for(var i =1;i<=$item.floor_column_count;i++){
							$('<li onclick="click_floor_row(this);" enter="no" style="left:'+(($item.floor_cell_width*i)+i)+'px;width:'+$item.floor_cell_width+'px;">'+$ul.find('li').length+'</li>').appendTo($ul);//添加列序号
							$content.find('ul').each(function(){
								$('<li id="floor_cell_f'+($floor.index()+1)+'_r'+($(this).index()+1)+'_c'+i+'" click="no" onclick="floor_cell_click(this);" style="left:'+(($item.floor_cell_width*(i-1))+(i-1))+'px;width:'+$item.floor_cell_width+'px;height:'+$item.floor_cell_height+'px;"></li>').appendTo($(this));//创建单元格
							});
						}
						for(var i in $item.floorCells){
							var _floor_product = $item.floorCells[i];
							
							var min_val_obj_0 = _floor_product.cell_row_index;
							var min_val_obj_1 = _floor_product.cell_column_index; 
							var _add_div_height = parseInt($item.floor_cell_height)*parseInt(_floor_product.cell_row_count);
							var _add_div_width = parseInt($item.floor_cell_width)*parseInt(_floor_product.cell_column_count);
							
							
							var $add_div = $('<div id="floor_cell_info_f'+$floor.index()+'_r'+min_val_obj_0+'_c'+min_val_obj_1+'_rcount'+_floor_product.cell_row_count+'_ccount'+_floor_product.cell_column_count+'" style="background:red;width:'+_add_div_width+'px;height:'+_add_div_height+'px;position: absolute;left:'+((parseInt($item.floor_cell_width)*(min_val_obj_1-1))+parseInt(min_val_obj_1))+'px;top:'+(parseInt($item.floor_cell_height)*(min_val_obj_0-1)+parseInt(min_val_obj_0)-1)+'px;"></div>').appendTo($floor.find("div.floor-content-values"));//添加处于顶层数据
							
							$('<img click="no" onclick="floor_img_click_operator(this);" width="'+_add_div_width+'" height="'+_add_div_height+'" src="'+_floor_product.cell_picture+'" />').appendTo($add_div);
							var $form = $('<form onsubmit="return false;"><input type="hidden" name="cell_row_count" /><input type="hidden" name="cell_column_count" /><input type="hidden" name="cell_row_index" /><input type="hidden" name="cell_column_index" /><input type="hidden" name="cell_ajax_method" /><input type="hidden" name="cell_ajax_url" /><input type="hidden" name="cell_ajax" /><input type="hidden" name="cell_name" /><input type="hidden" name="cell_id" /><input type="hidden" name="cell_picture" /></form>').appendTo($add_div);
							
							$form.form('load',_floor_product);//绑定数据是单元格中
						}
						
						/*初始化楼层的高度*/
						var row_count = $floor.find('div.floor-row li');
						var column_count = $floor.find('div.floor-column li');
						$floor.height(row_count.length*parseInt($item.floor_cell_height)+30+row_count.length);
						$floor.find('div.floor-not-allowed').height(row_count.length*parseInt($item.floor_cell_height)+30+row_count.length);
						$floor.find('div.floor-not-allowed').width(column_count.length*parseInt($item.floor_cell_width)+column_count.length);
						/*为楼层填充表单数据*/
						$floor.find('div.floor-info-form form').form('load',$item);
						$floor.find('div.floor-not-allowed').css('opacity',0.3);
						
						$floor = null;
					}});
				}
			});
	});
	
	function edit_floor(self){//修改楼层信息
		var $floor_from_obj = get_floor_for_index().find('div.floor-info-form form').serializeObject();
		$("#floor-info-dialog").dialog('open');
		$("#floor-info-dialog").find('form').form('load',$floor_from_obj);
	}
	
	function floor_locked_click(self){//解锁与锁定
		var $floor = $(self).parents('div.floor-list');
		$floor_click_index = $floor.index();
		var lock_floor = $floor.find('div.floor-locked-button input[name=floor-locked]');
		if(lock_floor.val()=='true'){
			lock_floor.val('false');
			$(self).text('锁定');
			$floor.find('div.floor-not-allowed').css({
				'opacity':0,
				'cursor':'default',
				'z-index':0
			});
			$floor.find('div.floor-info-menu').fadeIn();
			
			$("div.floors").find('div.floor-list').not($floor).each(function(){
				var $ff = $(this);
				var bbox = $ff.find('div.floor-locked-button');
				bbox.find('a').text('解锁');
				bbox.find('input[name=floor-locked]').val('true');
				$ff.find('div.floor-not-allowed').css({
					'opacity':0.3,
					'cursor':'not-allowed',
					'z-index':5
				});
				$ff.find('div.floor-info-menu').fadeOut();
			});
		}else{
			lock_floor.val('true');
			$(self).text('解锁');
			$floor.find('div.floor-not-allowed').css({
				'opacity':0.3,
				'cursor':'not-allowed',
				'z-index':5
			});
			$floor.find('div.floor-info-menu').fadeOut();
		}
		clean_floor_cell_infos($floor_click_index);
	}
	
	var floor_not_allowed_click_time_count = 0;
	var color_time = null;
	function floor_not_allowed_click(self){//锁定楼层情况下点击
		var $floor = $(self).parents('div.floor-list');
		if($floor.find('div.floor-locked-button input[name=floor-locked]').val()=='true'){
			var $floor_color = $floor.find('div.floor-locked-button a.floor-locked');
			var color = null;
			clearInterval(color_time);
			color_time = setInterval(function(){
				if(floor_not_allowed_click_time_count%2==0){
					color = 'red';
				}else{
					color = 'white';
				}
				if(floor_not_allowed_click_time_count>=6){
					$floor_color.removeAttr('style');
					floor_not_allowed_click_time_count =0;
					clearInterval(color_time);
				}else{
					floor_not_allowed_click_time_count++;
					$floor_color.css('color',color);
				}
			},50);
		}
	}
	
	function create_floor(){//创建楼层
		var $item = {
			"floor_name":"asdf",
			"floor_cell_width":100,
			"floor_cell_height":100,
			"floor_row_count":3,
			"floor_column_count":10,
			"sequence":0,
			"floorCells":[]
		};
		
		$.get('a.html',function(data){
			data = data.format({
				"floor_name":$item.floor_name,
				"floor-cell-width":$item.floor_cell_width,
				"floor-content-left":$item.floor_cell_width,
				"floor-content-values-left":$item.floor_cell_width,
				"floor-content-ul-height":$item.floor_cell_height
			});
			
			var $floor = $(data).appendTo($floors);
			var $ul = $floor.find('div.floor-column ul');
			var $ul_lis = $ul.find('li');
			var $content = $floor.find('div.floor-content');
			var $content_title = $floor.find('div.floor-row');
			for(var j =1;j<=$item.floor_row_count;j++){
				$('<li onclick="click_floor_row(this);" enter="no" style="width:'+$item.floor_cell_width+'px;height:'+$item.floor_cell_height+'px;line-height:'+$item.floor_cell_height+'px;">'+j+'</li>').appendTo($content_title.find('ul'));//添加行序号
				if(j<$item.floor_row_count){//此处判断是为了减少多增的一行
					var cont = ['<ul style="top:'+(($item.floor_cell_height*j)+j)+'px;">'];
					cont.push('</ul>');
					$(cont.join('')).appendTo($content);
				}
			}
			for(var i =1;i<=$item.floor_column_count;i++){
				$('<li onclick="click_floor_row(this);" enter="no" style="left:'+(($item.floor_cell_width*i)+i)+'px;width:'+$item.floor_cell_width+'px;">'+$ul.find('li').length+'</li>').appendTo($ul);//添加列序号
				$content.find('ul').each(function(){
					$('<li id="floor_cell_f'+($floor.index()+1)+'_r'+($(this).index()+1)+'_c'+i+'" click="no" onclick="floor_cell_click(this);" style="left:'+(($item.floor_cell_width*(i-1))+(i-1))+'px;width:'+$item.floor_cell_width+'px;height:'+$item.floor_cell_height+'px;"></li>').appendTo($(this));//创建单元格
				});
			}
			for(var i in $item.floor_products){
				var _floor_product = $item.floor_products[i];
				
				var min_val_obj_0 = _floor_product.product_row_index;
				var min_val_obj_1 = _floor_product.product_column_index; 
				var _add_div_height = parseInt($item.floor_cell_height)*parseInt(_floor_product.product_column_count);
				var _add_div_width = parseInt($item.floor_cell_width)*parseInt(_floor_product.product_row_count);
				
				
				var $add_div = $('<div id="floor_cell_info_f'+$floor.index()+'_r'+min_val_obj_0+'_c'+min_val_obj_1+'_rcount'+_floor_product.product_row_count+'_ccount'+_floor_product.product_column_count+'" style="background:red;width:'+_add_div_width+'px;height:'+_add_div_height+'px;position: absolute;left:'+((parseInt($item.floor_cell_width)*(min_val_obj_1-1))+parseInt(min_val_obj_1))+'px;top:'+(parseInt($item.floor_cell_height)*(min_val_obj_0-1)+parseInt(min_val_obj_0)-1)+'px;"></div>').appendTo($floor.find("div.floor-content-values"));//添加处于顶层数据
				
				$('<img click="no" onclick="floor_img_click_operator(this);" width="'+_add_div_width+'" height="'+_add_div_height+'" src="'+_floor_product.product_picture+'" />').appendTo($add_div);
				var $form = $('<form onsubmit="return false;"><input type="hidden" name="cell_row_count" /><input type="hidden" name="cell_column_count" /><input type="hidden" name="cell_row_index" /><input type="hidden" name="cell_column_index" /><input type="hidden" name="cell_ajax_method" /><input type="hidden" name="cell_ajax_url" /><input type="hidden" name="cell_ajax" /><input type="hidden" name="cell_name" /><input type="hidden" name="cell_id" /><input type="hidden" name="cell_picture" /></form>').appendTo($add_div);
				
				$form.form('load',_floor_product);//绑定数据是单元格中
			}
			
			/*初始化楼层的高度*/
			var row_count = $floor.find('div.floor-row li');
			var column_count = $floor.find('div.floor-column li');
			$floor.height(row_count.length*parseInt($item.floor_cell_height)+30+row_count.length);
			/*为楼层填充表单数据*/
			$floor.find('div.floor-info-form form').form('load',$item);
			$floor.find('div.floor-not-allowed').height(row_count.length*parseInt($item.floor_cell_height)+30+row_count.length);
			$floor.find('div.floor-not-allowed').width(column_count.length*parseInt($item.floor_cell_width)+column_count.length);
			$floor.find('div.floor-not-allowed').css('opacity',0.3);
		});
	}
	
	function clean_floor_datas(self){//清空楼层数据
		$floor_click_index = $(self).parents('div.floor-list').index();
		$floor = get_floor_for_index();
		var $contents = $floor.find('div.floor-content-values form input[name=product_id][value!=""]');
		$contents.each(function(){
			console.info('id:'+$(this).val());
		});
	}
	
	
	function delete_floor(self){
		$(self).parents('div.floor-list').remove();
	}

	function floor_add_column(){
		
	}
	function floor_add_row(){
		
	}
	
	function save_floor_cell(){//保存楼层单元格信息
		/*************************/
		
		var serializeData = $("#floor-cell-dialog").find('form').serializeObject();
		
		if(floor_cell_sort_groups.length>0){
			var min_val_obj = floor_cell_sort_groups[0];
			var max_val_obj = floor_cell_sort_groups[floor_cell_sort_groups.length-1];
			
			var min_val_obj_0 = min_val_obj[0].split('-')[0];
			var min_val_obj_1 = min_val_obj[0].split('-')[1];
			
			var max_val_obj_0 = max_val_obj[0].split('-')[0];
			var max_val_obj_1 = max_val_obj[max_val_obj.length-1].split('-')[1];
			
			var _add_div_height = $floor_cell_height*((max_val_obj_0-min_val_obj_0)+1);
			var _add_div_width = $floor_cell_width*((parseInt(max_val_obj_1)-parseInt(min_val_obj_1))+1);
			
			
			var $add_div = $('<div id="floor_cell_info_f'+$floor_click_index+'_r'+min_val_obj_0+'_c'+min_val_obj_1+'_rcount'+((max_val_obj_0-min_val_obj_0)+1)+'_ccount'+((parseInt(max_val_obj_1)-parseInt(min_val_obj_1))+1)+'" style="background:red;width:'+_add_div_width+'px;height:'+_add_div_height+'px;position: absolute;left:'+(($floor_cell_width*(min_val_obj_1-1))+parseInt(min_val_obj_1))+'px;top:'+($floor_cell_height*(min_val_obj_0-1)+parseInt(min_val_obj_0)-1)+'px;"></div>').appendTo($('div.floor-list').eq($floor_click_index).find("div.floor-content-values"));//添加处于顶层数据
			
			$('<img click="no" onclick="floor_img_click_operator(this);" width="'+_add_div_width+'" height="'+_add_div_height+'" src="'+serializeData.cell_picture+'" />').appendTo($add_div);
			var $form = $('<form onsubmit="return false;"><input type="hidden" name="cell_id" /><input type="hidden" name="cell_name" /><input type="hidden" name="cell_ajax" /><input type="hidden" name="cell_ajax_url" /><input type="hidden" name="cell_ajax_method" /><input type="hidden" name="cell_column_index" /><input type="hidden" name="cell_row_index" /><input type="hidden" name="cell_column_count" /><input type="hidden" name="cell_row_count" /></form>').appendTo($add_div);
			
			$form.form('load',serializeData);//绑定数据是单元格中
			
			clean_floor_cell_infos();
			
			$("#floor-cell-dialog").find('form').form('clear');
		}else{
			var img_click_yes = get_floor_for_index().find('div.floor-content-values').find('img[click=yes]').attr('click','no').parent();
			img_click_yes.find('form').form('load',serializeData);
			img_click_yes.find('img[click!=""]').attr('src',serializeData.picture);
			get_floor_for_index().find('div.floor-img-click-operator').hide();
		}
		cancel_floor_cell();
		
	}
	
	function floor_img_click_operator(self){
		var $self = $(self);
		$floor_click_index = $self.parents('div.floor-list').index();
		
		var $floor_from_obj = get_floor_for_index().find('div.floor-info-form form').serializeObject();
		
		var $self_div = $self.parent();
		var _id = $self_div.attr('id').slice(16);
		var _f_index = _id.split('_')[0].slice(1);
		var _r_index = _id.split('_')[1].slice(1);
		var _c_index = _id.split('_')[2].slice(1);
		var _rcount = _id.split('_')[3].slice(6);
		var _ccount = _id.split('_')[4].slice(6);
		
		if($self.attr('click')=='no'){
			$self.attr('click','yes');
		}else{
			$self.attr('click','no');
		}
		var floor_img_operator = get_floor_for_index().find('div.floor-img-click-operator');
		get_floor_for_index().find('div.floor-content-values img[click=yes]').not($self).attr('click','no');
		if($self.attr('click')=='yes'){
			floor_img_operator.css({
				'left':parseInt($floor_from_obj.floor_cell_width)*_c_index+(parseInt($floor_from_obj.floor_cell_width)*_ccount/2)-100/2,
				'top':parseInt($floor_from_obj.floor_cell_height)*_r_index+(parseInt($floor_from_obj.floor_cell_height)*(_rcount-1)/2)-10/2-30
			}).show();
		}else{
			floor_img_operator.hide();
		}
		
		clean_floor_cell_infos();
	}
	
	function floor_img_cancel_operator(self){
		var $self = $(self);
		$floor_click_index = $self.parents('div.floor-list').index();
		
		var floor_img_operator = get_floor_for_index().find('div.floor-img-click-operator');
		get_floor_for_index().find('div.floor-content-values img[click=yes]').attr('click','no');
		floor_img_operator.hide();
	}
	
	function floor_img_edit_operator(self){
		var $self = $(self);
		$floor_click_index = $self.parents('div.floor-list').index();
		var click_node = get_floor_for_index().find('div.floor-content-values img[click=yes]');
		var serializeData = click_node.parent().find('form').serializeObject();
		floor_click_operator_edit(serializeData);
		
		clean_floor_cell_infos();
	}
	
	function floor_img_del_operator(self){//删除楼层单元格信息
		var $self = $(self);
		$floor_click_index = $self.parents('div.floor-list').index();
		$floor = get_floor_for_index();
		var img_node = $floor.find('div.floor-content-values').find('img[click=yes]');
		img_node.parent().remove();
		
		$floor.find('div.floor-img-click-operator').hide();
	}
	
	function clean_floor_cell_infos(index){//清空单元格所有数据（初始化）
		floor_cell_sort_groups = [];
		$floor_click_cells = [];
		$floor_click_index = null;
		_$row_val = null;//行数据
		_$col_val = null;//列数据
		_$row_exit_val = [];//已经存在的行序号
		_$col_exit_val = [];//已经存在的列序号
		var $floor = null;
		if(index){
			$floor = $('div.floor-list').eq(index);
		}else{
			$floor = get_floor_for_index();
		}
		hide_click_operator($floor.find('div.floor-click-operator'));
		$floor.find('div.floor-content li[click=yes]').attr('click','no').removeClass('floor-click-color');
	}
	
	function clean_floor_cell_img(){
		var $floor = get_floor_for_index();
		$floor.find('div.floor-content-values').find('img[click=yes]').attr('click','no');
		$floor.find('div.floor-img-click-operator').hide();
	}
	
	function cancel_floor_cell(){//取消保存楼层单元格信息
		$("#floor-cell-dialog").dialog('close');
	}
	
	function create_floor_columns(floor){
		var $floor = $(floor);
		var $floor_from_obj = $floor.find('div.floor-info-form form').serializeObject();
		var $row = $floor.find('div.floor-row').find('ul');
		var $row_lis = $row.find('li');
		var $content = $floor.find('div.floor-content');
		var $content_uls = $content.find('ul');
		var $column = $floor.find('div.floor-column').find('ul');//查找列序号对象
		var $column_lis = $column.find('li');
		$('<li onclick="click_floor_row(this);" enter="no" style="left:'+((parseInt($floor_from_obj.floor_cell_width)*($column_lis.length))+$column_lis.length)+'px;width:'+$floor_from_obj.floor_cell_width+'px;">'+($column_lis.length)+'</li>').appendTo($column);
		$content_uls.each(function(){
			$('<li id="floor_cell_f'+($floor.index()+1)+'_r'+($(this).index()+1)+'_c'+$column_lis.length+'" click="no" onclick="floor_cell_click(this);" style="left:'+((($column_lis.length-1)*parseInt($floor_from_obj.floor_cell_width))+($column_lis.length-1))+'px;width:'+$floor_from_obj.floor_cell_width+'px;height:'+$floor_from_obj.floor_cell_height+'px;"></li>').appendTo($(this));
		});
		
		var row_count = $floor.find('div.floor-row li');
		var column_count = $floor.find('div.floor-column li');
		$floor.find('div.floor-not-allowed').width(column_count.length*parseInt($floor_from_obj.floor_cell_width)+column_count.length);
		$floor.find('div.floor-not-allowed').css('opacity',0.3);
	}
	
	function create_floor_row(floor){
		var $floor = $(floor);
		var $floor_from_obj = $floor.find('div.floor-info-form form').serializeObject();
		var $columns = $floor.find('div.floor-column').find('li');
		var $row = $floor.find('div.floor-row').find('ul');
		var $row_lis = $row.find('li');//得到行数
		var _row = $('<li onclick="click_floor_row(this);" enter="no" style="width:'+$floor_from_obj.floor_cell_width+'px;height:'+$floor_from_obj.floor_cell_height+'px;line-height:'+$floor_from_obj.floor_cell_height+'px;">'+($row_lis.length+1)+'</li>').appendTo($row);//添加新一行
		var conte = ['<ul style="top:'+((_row.index()*parseInt($floor_from_obj.floor_cell_height))+_row.index())+'px;">'];//添加新行的数组
		for(var i =0;i<$columns.length-1;i++){//减一是为了除去序列行号
			conte.push('<li id="floor_cell_f'+($floor.index()+1)+'_r'+($row_lis.length+1)+'_c'+(i+1)+'" click="no" onclick="floor_cell_click(this);" style="left:'+((i*$floor_cell_width)+i)+'px;width:'+$floor_from_obj.floor_cell_width+'px;height:'+$floor_from_obj.floor_cell_height+'px;"></li>');
		}
		conte.push('</ul>');
		$(conte.join('')).appendTo($floor.find('div.floor-content'));
		
		var row_count = $floor.find('div.floor-row li');
		$floor.height(row_count.length*parseInt($floor_from_obj.floor_cell_height)+30+row_count.length);
		$floor.find('div.floor-not-allowed').height(row_count.length*parseInt($floor_from_obj.floor_cell_height)+30+row_count.length);
	}
	
	function floor_cell_click(self){
		change_cell_bgcolor(self);//改变选中单元格的颜色
		push_cell_position(self);//把选中的单元格位置放入数组中
		clean_floor_cell_img();//还原带数据的单元格
	}
	
	function change_cell_bgcolor(self){//修变单元格颜色
		var $self = $(self);
		if($self.attr('click')=='no'){
			$self.attr('click','yes');
		}else{
			$self.attr('click','no');
		}
		
		if($self.attr('click')=='yes'){//双重保障
			$self.addClass('floor-click-color');
		}else{
			$self.removeClass('floor-click-color');
		}
	}
	
	function push_cell_position(self){
		var $self = $(self);
		$floor_click_cells = [];
		var $floor = $self.parents('div.floor-list');
		$floor_click_index = $floor.index();//把楼层索引放到公共变量中
		var $row = $floor.find('div.floor-content');
		var $clicks = $row.find('li[click=yes]');//查询当前楼层所选中的li
		$clicks.each(function(){
			var $myself = $(this);
			var $id = $myself.attr('id');
			var $id_rcs = $id.slice(14).split('_');
			var $id_row = $id_rcs[0].slice(1);
			var $id_column = $id_rcs[1].slice(1);
			$floor_click_cells.push([$id_row,$id_column]);
		});
		check_cell_point_yes($floor_click_cells);//检查选中的位置是否符合要求
	}
	
	var _$row_val = null;//行数据
	var _$col_val = null;//列数据
	var _$row_exit_val = [];//已经存在的行序号
	var _$col_exit_val = [];//已经存在的列序号
	function check_cell_point_yes(cells){
		if(cells.length>0){
			var ass_row = false;
			var ass_col = false;
			_$row_exit_val = [];//清空原有值
			_$col_exit_val = [];//清空原有值
			for(var cell in cells){
				_$row_val = cells[cell][0];//获取行数据
				_$col_val = cells[cell][1];//获取列数据
				
				floor_push_cell_row_index(_$row_val);//将行序列号压入数组中
				floor_push_cell_col_index(_$row_val,_$col_val);//将列序列号组合后压入数组中
			}
			
			floor_push_cell_sort_group();//将列号分组排序后压入数组中
			
			if(check_floor_push_cell_row_index()&&check_floor_push_cell_col_index()){
				show_floor_cell_operaotr();//根据规则是否显示单元格
				floor_cell_verity_yes();//'符合规则';
			}else{
				floor_cell_verity_not();//'不符合规则';
			}
		}else{
			hide_click_operator($("div.floor-list").eq($floor_click_index).find('div.floor-click-operator'));//当前点击的单元格为空的时候隐藏单元格操作
		}
	}
	
	function floor_click_operator_edit(serializeData){
		$("#floor-cell-dialog").dialog('open');
		console.info(serializeData);
		$("#floor-cell-dialog").find('form').form('clear').form('load',serializeData);
	}
	
	function floor_click_operator_cancel(self){
		var $floor = $(self).parents('div.floor-list');//获取楼层jquery对象
		var $click_node = $floor.find('div.floor-content li[click=yes]');
		$click_node.attr('click','no').removeClass('floor-click-color');
		hide_click_operator($floor.find('div.floor-click-operator'));
	}
	
	function show_click_operator(self){//显示单元格操作
		self.show();
	}
	
	function hide_click_operator(self){//隐藏单元格操作
		self.hide();
	}
	
	function floor_cell_verity_yes(){//单元格点击位置验证通过
		var $floor = $('div.floor-list').eq($floor_click_index);//获取楼层jquery对象
		var $click_node = $floor.find('div.floor-click-operator');
		show_click_operator($click_node);
	}
	
	function floor_cell_verity_not(){//单元格点击位置验证不通过
		var $floor = $('div.floor-list').eq($floor_click_index);//获取楼层jquery对象
		var $click_node = $floor.find('div.floor-click-operator');
		hide_click_operator($click_node);
	}
	
	function show_floor_cell_operaotr(){
		var $floor_click_operator = $('div.floor-list').eq($floor_click_index).find(".floor-click-operator");
		
		var $floor_from_obj = get_floor_for_index().find('div.floor-info-form form').serializeObject();
		if(floor_cell_sort_groups.length>0){
			if(floor_cell_sort_groups.length==1){
				var gs = floor_cell_sort_groups[0];
				if(gs.length>1){
					var min_val = gs[0];
					var max_val = gs[gs.length-1];
					var column_width = (max_val.split('-')[1]-min_val.split('-')[1]+1);
					
					var min_val_0 = min_val.split('-')[0];
					var min_val_1 = min_val.split('-')[1];
					var max_val_0 = max_val.split('-')[0];
					var max_val_1 = max_val.split('-')[1];
					
					var id_obj = get_floor_for_index().find('div.floor-content').find('li#floor_cell_f'+(get_floor_for_index().index()+1)+'_r'+min_val_0+'_c'+min_val_1);
					var left = parseInt(id_obj.css('left'));
					var top = parseInt(id_obj.parent().css('top'));
					
					
					var $cell_obj = $('div.floor-content li#floor_cell_f'+($floor_click_index+1)+'_r'+min_val_0+'_c'+max_val_0);
					$floor_click_operator.css({
						'left':(parseInt($floor_from_obj.floor_cell_width)*min_val_1)+(parseInt($floor_from_obj.floor_cell_width)*(max_val_1-min_val_1)/2)+$floor_cell_operator_div_width/2,
						'top':(parseInt($floor_from_obj.floor_cell_height)*(min_val_0-1))+(parseInt($floor_from_obj.floor_cell_height)*(max_val_0-min_val_0+1)/2)+29-$floor_cell_operator_div_height/2
					});
				}else{
					var min_val = gs[0];
					var min_val_0 = min_val.split('-')[0];
					var min_val_1 = min_val.split('-')[1];
					var id_obj = get_floor_for_index().find('div.floor-content').find('li#floor_cell_f'+(get_floor_for_index().index()+1)+'_r'+min_val_0+'_c'+min_val_1);
					var left = parseInt(id_obj.css('left'));
					var top = parseInt(id_obj.parent().css('top'));
					$floor_click_operator.css({
						'left':(left+parseInt($floor_from_obj.floor_cell_width))+$floor_cell_operator_div_width/2,
						'top':(top+parseInt($floor_from_obj.floor_cell_height))-29
					});
				}
			}else{
				var min_gs = floor_cell_sort_groups[0];
				var max_gs = floor_cell_sort_groups[floor_cell_sort_groups.length-1];
				
				var min_val = min_gs[0];
				var max_val = max_gs[max_gs.length-1];
				
				var min_val_0 = min_val.split('-')[0];
				var min_val_1 = min_val.split('-')[1];
				
				var max_val_0 = max_val.split('-')[0];
				var max_val_1 = max_val.split('-')[1];
				
				$floor_click_operator.css({
					'left':parseInt($floor_from_obj.floor_cell_width)*min_val_1+((max_val_1-min_val_1)*$floor_from_obj.floor_cell_width)/2+$floor_cell_operator_div_width/2,
					'top':parseInt($floor_from_obj.floor_cell_height)*min_val_0+((max_val_0-min_val_0)*$floor_from_obj.floor_cell_height)/2-29
				});
				
			}
		}
	}
	
	function floor_push_cell_row_index(row_val){//把选中的行号压入数组中
		var _pass_row_exit_val = true;
		for(var _excell in _$row_exit_val){
			if(_$row_exit_val[_excell]==row_val){
				_pass_row_exit_val = false;
				break;
			}
		}
		if(_pass_row_exit_val||_$row_exit_val.length==0){
			_$row_exit_val.push(row_val);
		}
	}
	
	function floor_push_cell_col_index(row_val,col_val){//把选中的列号压入数组中
		var _pass_col_exit_val = true;
		for(var _excell in _$col_exit_val){
			if(_$col_exit_val[_excell]==(row_val+'-'+col_val)){
				_pass_col_exit_val = false;
				break;
			}
		}
		if(_pass_col_exit_val||_$col_exit_val.length==0){
			_$col_exit_val.push((row_val+'-'+col_val));
		}
	}
	
	function check_floor_push_cell_col_index(){//检查列号是否符合规则
		/* 进行一轮简单判断(每行长度) */
		var first_length = floor_cell_sort_groups[0].length;
		for(var item in floor_cell_sort_groups){
			if(first_length!=floor_cell_sort_groups[item].length){
				return false;
			}
		}
		/* 进行第二轮判断(每行的索引数据) */
		var first_groups = floor_cell_sort_groups[0];
		for(var item in floor_cell_sort_groups){
			var ggs = floor_cell_sort_groups[item];
			for(var i =0;i<first_groups.length;i++){
				if(first_groups[i].split('-')[1]!=ggs[i].split('-')[1]){
					return false;
				}
			}
		}
		/* 第行第三轮判断(索引连续) */
		for(var item in floor_cell_sort_groups){
			var ggs = floor_cell_sort_groups[item];
			var ggs_min_val = ggs[0].split('-')[1];
			var ggs_max_val = ggs[ggs.length-1].split('-')[1];
			if((ggs_max_val-ggs_min_val)!=(ggs.length-1)){
				return false;
			}
		}
		return true;
	}
	
	var floor_cell_sort_groups = [];//分行排序单元格位置
	function floor_push_cell_sort_group(){//将列号分组排序后压入数组中
		floor_cell_sort_groups = [];
		var _groups = [];
		var _first_val = null;
		for(var item in _$col_exit_val){
			var val = _$col_exit_val[item];
			if(_first_val&&_first_val!=val.split('-')[0]){
				floor_cell_sort_groups.push(_groups);
				_groups = [];
			}
			_groups.push(val);
			if(val){
				_first_val = val.split('-')[0];
			}
		}
		floor_cell_sort_groups.push(_groups);
	}
	
	function check_floor_push_cell_row_index(){//检查行号是否符合规则
		var _$row_exit_val_length = _$row_exit_val.length;
		if(_$row_exit_val_length.length!=1){
			var arr_min_val = _$row_exit_val[0];//数组中最小的值
			var arr_max_val = _$row_exit_val[_$row_exit_val.length-1];//数组中最大的值
			if((arr_max_val-arr_min_val)!=(_$row_exit_val.length-1)){//最大值减去最小值等于长度证明符号规则
				return false;
			}
		}
		return true;
	}
	
	var click_floor_row_time = null;
	var click_floor_row_time_y = false;
	function click_floor_row(self){//点击序列号
		click_floor_row_time_y = false;
		var $self = $(self);
		$floor_click_index = $self.parents('div.floor-list').index();
		$floor = get_floor_for_index();
		var $floor_from_obj = $floor.find('div.floor-info-form form').serializeObject();
		clearTimeout(click_floor_row_time);
		click_floor_row_time = setTimeout(function(){
			if(!click_floor_row_time_y){
				$floor.find('div.floor-row-operator').hide();
				$floor.find('div.floor-column').find('li[enter=yes]').attr('enter','no');//清除列
				$floor.find('div.floor-row').find('li[enter=yes]').attr('enter','no');//清除行
			}
		},3000);
		
		if($self.parents('div.floor-column').length==1){
			$floor.find('div.floor-row-operator').css({
				'top':4,
				'left':parseInt($floor_from_obj.floor_cell_width)*$self.index()+$self.index()
			}).show().find('a').text('删列');
			$floor.find('div.floor-column').find('li[enter=yes]').attr('enter','no');//清除列
			$floor.find('div.floor-row').find('li[enter=yes]').attr('enter','no');//清除行
			$self.attr('enter','yes');
		}else if($self.parents('div.floor-row').length==1){
			$floor.find('div.floor-row-operator').css({
				'top':parseInt($floor_from_obj.floor_cell_height)*$self.index()+30+parseInt($floor_from_obj.floor_cell_height)/2-22/2+$self.index(),
				'left':4
			}).show().find('a').text('删行');
			$floor.find('div.floor-column').find('li[enter=yes]').attr('enter','no');//清除列
			$floor.find('div.floor-row').find('li[enter=yes]').attr('enter','no');//清除行
			$self.attr('enter','yes');
		}
		
	}
	
	function floor_row_or_col_click(self){//删除楼层的列或行
		click_floor_row_time_y = true;
		var $self = $(self);
		$floor_click_index = $self.parents('div.floor-list').index();
		$floor = get_floor_for_index();
		var delete_ids = [];//删除列或行中有关联的图片数据
		var contents = get_floor_for_index().find('div.floor-content-values div');
		if($floor.find('div.floor-column').find('li[enter=yes]').length==1){//删除列
			var click_obj = $floor.find('div.floor-column').find('li[enter=yes]');
			
			//以下是对已经保存的图片数据对行操作
			
			contents.each(function(){
				var my = $(this);
				var _id = my.attr('id');
				//进行一层判断（相同列）
				var _ids = _id.slice(16).split('_');
				var f_index = _ids[0].slice(1);//楼层索引
				var r_index = _ids[1].slice(1);//楼层行索引
				var c_index = _ids[2].slice(1);//楼层列索引
				var rcount_index = _ids[3].slice(6);//楼层行占宽
				var ccount_index = _ids[4].slice(6);//楼层列占宽
				if(c_index<=click_obj.index()&&click_obj.index()<=(parseInt(c_index)+parseInt(ccount_index)-1)){
					delete_ids.push(_id);
				}
			});
			
			if(delete_ids.length>0){
				$.messager.confirm('提示','确定要删除关联此行中的数据吗?',function(r){
					if(r){
						if(click_obj.index()==$floor.find('div.floor-column li').length-1){//删除最后一行
							$floor.find('div.floor-content ul').each(function(){
								$(this).find('li:last').remove();
								$(this).find('li').eq(click_obj.index()).remove();
							});
						}else{
							$floor.find('div.floor-content ul').each(function(){
								$(this).find('li').eq(click_obj.index()).nextAll().each(function(){
									$(this).css({
										'left':parseInt($(this).css('left'))-$floor_cell_width-1
									});
								});
								$(this).find('li').eq(click_obj.index()).remove();
								$(this).find('li').each(function(){//对ID编号从新编排
									var _id = $(this).attr('id');
									$(this).attr('id',_id.slice(0,_id.lastIndexOf('_c')+2)+($(this).index()+1));
								});
							});
						}
						click_obj.nextAll().each(function(){
							$(this).css({
								'left':parseInt($(this).css('left'))-$floor_cell_width-1
							});
						});
						click_obj.remove();
						$floor.find('div.floor-column li:gt(0)').each(function(){//对列序号从新排序
							$(this).text($(this).index());
						});
						
						
					}
				});
			}
			
			
		}else{//删除行
			var click_obj = $floor.find('div.floor-row').find('li[enter=yes]');
			
			//以下是对已经保存的图片数据对行操作
			
			contents.each(function(){
				var my = $(this);
				var _id = my.attr('id');
				//进行一层判断（相同列）
				var _ids = _id.slice(16).split('_');
				var f_index = _ids[0].slice(1);//楼层索引
				var r_index = _ids[1].slice(1);//楼层行索引
				var c_index = _ids[2].slice(1);//楼层列索引
				var rcount_index = _ids[3].slice(6);//楼层行占宽
				var ccount_index = _ids[4].slice(6);//楼层列占宽
				
				if(r_index<=(click_obj.index()+1)&&(click_obj.index()+1)<=(parseInt(r_index)+parseInt(rcount_index)-1)){
					delete_ids.push(_id);
				}
			});
			
			//***************
			
			if(delete_ids.length>0){
				$.messager.confirm('提示','确定要删除关联此行中的数据吗?',function(r){
					if(r){
						$floor.find('div.floor-content ul').eq(click_obj.index()).remove();//删除content数据
						$floor.find('div.floor-row li').eq(click_obj.index()).remove();
						
						$floor.find('div.floor-content ul').each(function(){//重新排序
							$(this).css({
								'top':$floor_cell_height*$(this).index()+$(this).index()
							});
						});
						$floor.find('div.floor-row li').each(function(){
							$(this).text($(this).index()+1);
						});
						
						
					}
				});
			}
		}
		
		$floor.find('div.floor-content li[click=yes]').attr('click','no').removeClass('floor-click-color');
		$floor.find('div.floor-click-operator').hide();
		$floor.find('div.floor-row-operator').hide();
		
	}
	
	
	function get_floor_for_index(){
		return $('div.floor-list').eq($floor_click_index);
	}
	
	function floor_info_title_enter(self){//鼠标滑过楼层标题
		$(self).find('div.floor-info-menu').fadeIn();
	}
	function floor_info_title_leave(self){//鼠标滑过楼层标题
		$(self).find('div.floor-info-menu').hide();
	}
</script>
